#pragma once


class XamlReader;

class XamlSchemaContext;
class XamlTextReaderSettings;

#include "XamlOptimizedNodeList.h"


class XamlNodeStreamCacheManager
{
public: 
	class NodeStreamCacheEntry
	{

	private: 
		NodeStreamCacheEntry();
	public: 
		static HRESULT Create(const xshared_ptr<CXString> & spUniqueName, xshared_ptr<XamlNodeStreamCacheManager::NodeStreamCacheEntry> & spNodeStreamCacheEntry);
		XUINT32 GetAccessCount();
		void IncrementAccessCount();
		HRESULT SetNodeList(const xshared_ptr<XamlOptimizedNodeList> & spXamlOptimizedNodeList);
		HRESULT GetXamlReader(xshared_ptr<XamlReader> & spXamlReader);
		XBOOL HasNodeList();
	private: 
		xshared_ptr<XamlOptimizedNodeList> m_spNodeList;
		XUINT32 m_uiAccessCount;
	};

	static HRESULT Create(xshared_ptr<XamlNodeStreamCacheManager> & spXamlNodeStreamCacheManager);
	HRESULT HasCacheForUri(const CXString & strUri, XBOOL * pfHasCachedNodelist);
	HRESULT GetXamlReader(xshared_ptr<XamlSchemaContext> & spXamlSchemaContext, const xshared_ptr<CXString> & spUniqueName,XUINT32 cSource, XUINT8 * pSource, xshared_ptr<XamlTextReaderSettings> & spXamlTextReaderSettings, xshared_ptr<XamlReader> & spXamlReader);
	HRESULT Flush();
	HRESULT SetCacheEnabled(XBOOL fEnabled);
	XBOOL GetCacheEnabled();
	HRESULT SetFoundIgnoredUsingXmlns();
	HRESULT FlushIfNeeded();

private: 
	XamlNodeStreamCacheManager();
	HRESULT EnsureCacheEntry(const CXString & strUniqueName, xshared_ptr<XamlNodeStreamCacheManager::NodeStreamCacheEntry> & spNodeStreamCacheEntry);
	HRESULT EnsureCacheEntry(const xshared_ptr<CXString> & spUniqueName, xshared_ptr<XamlNodeStreamCacheManager::NodeStreamCacheEntry> & spNodeStreamCacheEntry);
	xstringmap<xshared_ptr<XamlNodeStreamCacheManager::NodeStreamCacheEntry> > m_UriToNodelistMap;  

	struct
	{
		XUINT32 m_fCacheEnabled:1;
		XUINT32 m_bFoundIgnoredUsingXmlns:1;
	};


};
